//
//  CommentCell.m
//  Final
//
//  Created by student on 2021/12/14.
//  Copyright © 2021 Lenrony. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CommentCell.h"

@interface CommentCell (){
    float screen_width;
    float screen_height;
}

@property(strong, nonatomic) RawUser* rawuser;
@property(strong, nonatomic) NSString* content;

@property(strong, nonatomic) UIViewController* scv;

@property(strong, nonatomic) RawUserView* ruv;
@property(strong, nonatomic) UILabel* label;
@property(strong, nonatomic) UILabel* timeLabel;

@end

@implementation CommentCell

-(void)setRawUser: (RawUser*)rawuser
       andContent: (NSString*)content
          andTime: (NSString*)timestamp
andViewController: (UIViewController*)scv
{
    self.rawuser = rawuser;
    self.content = content;
    self.scv = scv;
    screen_width = [UIScreen mainScreen].bounds.size.width;
    screen_height = [UIScreen mainScreen].bounds.size.height;
    [self setBackgroundColor:[UIColor whiteColor]];
    
    self.ruv = [[RawUserView alloc]initWithRawUser:rawuser andViewController:self.scv];
    [self.ruv setFrame:CGRectMake(0, 0, 80, 40)];
    [self addSubview:self.ruv];
    
    self.label = [[UILabel alloc]initWithFrame:CGRectMake(5, 50, self.bounds.size.width - 10, 40)];
    self.label.font = [UIFont systemFontOfSize:18];
    self.label.numberOfLines = 0;
    self.label.textAlignment = NSTextAlignmentLeft;
    self.label.text = self.content;
    CGSize size = [content boundingRectWithSize:CGSizeMake(self.bounds.size.width - 10, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.label.font} context:nil].size;
    [self.label setFrame:CGRectMake(5, 50, size.width, size.height)];
    [self addSubview:self.label];
    
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(screen_width / 2, 10, screen_width / 2 - 10, 20)];
    self.timeLabel.text = timestamp;
    self.timeLabel.textColor = [UIColor grayColor];
    self.timeLabel.textAlignment = NSTextAlignmentRight;
    [self.timeLabel setFont:[UIFont systemFontOfSize:16]];
    [self addSubview:self.timeLabel];
}

@end
